import { Indicator } from "mint-ui";
import Header from '../../packages/header';
import Popup from '../../packages/popup';
import Picker from '../../packages/picker';
import DatetimePicker from '../../packages/datetime-picker';
import MessageBox from '../../packages/message-box';
import Toast from '../../packages/toast';
import Spinner from '../../packages/spinner';
import Keyboard from '../../packages/keyboard';
import Upload from '../../packages/upload';
import ActionSheet from '../../packages/actionSheet';

const components = {
  Header,
  Popup,
  Picker,
  DatetimePicker,
  Spinner,
  Keyboard,
  Upload,
  ActionSheet,
};

const install = function install(Vue, config = {}) {
  if (install.installed) return;
  Object.keys(components).forEach((key) => {
    Vue.component(components[key].name, components[key]);
  });

  Vue.$messagebox = Vue.prototype.$messagebox = MessageBox;
  Vue.$toast = Vue.prototype.$toast = Toast;
  Vue.$indicator = Vue.prototype.$indicator = Indicator;
};

// auto install
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue);
};

export {
  install,
  Header,
  Popup,
  Picker,
  DatetimePicker,
  MessageBox,
  Toast,
  Spinner,
  Keyboard,
  Upload,
  ActionSheet,
};
